export default {
    namespaced: true,
    state: () => ({
        contacts: [
            {
                id: 1,
                name: '张三',
                tel: 123456789,
                address: '年少多金',
                isDefault: true
            },
            {
                id: 2,
                name: 'lisi',
                tel: 123456789,
                address: '年少多金',
                isDefault: false
            }
        ]
    }),
    mutations: {
        add_contact (state, contact) {
            const defaultContactIndex = state.contacts.findIndex(contact => contact.isDefault)
            state.contacts.unshift(contact)
            if (contact.isDefault && defaultContactIndex !== -1) {
                state.contacts[defaultContactIndex].isDefault = false
            }
            state.contacts.unshift(contact)
            }
        }
    }